﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using DBControl;
using Wuqi.Webdiyer;

namespace Newsell
{
    public partial class Default : TopBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getTotalCount();
                BindbuyInfo();
            }
        }

        #region buy event
        /// <summary>
        /// 绑定买家需求数据
        /// </summary>
        private void BindbuyInfo()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlwhere = " where [Status]=0 and [bsc]=0 or [Status]=0 and [bsc]<>0 and [rsn] <> '" + Session["usNick"].ToString() + "'";
            SqlParameter p1 = new SqlParameter("@tablename", "GetDateByUser");//视图名或表名
            SqlParameter p2 = new SqlParameter("@pagerow", this.listupPager.PageSize);         //每页显示记录数 
            SqlParameter p3 = new SqlParameter("@pagenow", this.listupPager.CurrentPageIndex); //当前显示第几页 
            SqlParameter p4 = new SqlParameter("@ordercol", "Starttime");//排序字段
            SqlParameter p5 = new SqlParameter("@order", 1);//排序顺序，0升序，1降序
            SqlParameter p6 = new SqlParameter("@where", sqlwhere);
            SqlParameter[] paras = new SqlParameter[] { p1, p2, p3, p4, p5, p6 };
            this.RepSellMain.DataSource = sdh.ExecuteDataTable("sp_page", System.Data.CommandType.StoredProcedure, null, paras);
            RepSellMain.DataBind();
        }
        /// <summary>
        /// 获得买家需求总数，分页使用
        /// </summary>
        private void getTotalCount()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlcount = "SELECT COUNT(*) FROM GetDateByUser where [Status]=0 and [bsc]=0 or [Status]=0 and [bsc]<>0 and [rsn] <> '" + Session["usNick"].ToString() + "'";
            this.listupPager.RecordCount = int.Parse(sdh.ExecuteScalar(sqlcount).ToString());
        }
        /// <summary>
        /// 翻页，此处需要绑定要执行的js函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void listupPager_PageChanged(object sender, EventArgs e)
        {
            BindbuyInfo();
            execStartupjs();
        }
        #endregion buy event
       
        #region common event
        /// <summary>
        /// 执行js函数
        /// </summary>
        protected void execStartupjs() 
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "documentready", "<script>ResizeImg();infoDeCode();slideDetail();goodContToggle();</script>", false);
        }
        #endregion common event 
    }
}